Skip to content

Use fitted rows for binned residuals with na.exclude - #1039

Merged
strengejacke merged 1 commit into
easystats:mainfrom
yucheng-du:fix/binned-residuals-excluded-rows
Dec 2, 2026
Merged

strengejacke merged 1 commit into
easystats:mainfrom
yucheng-du:fix/binned-residuals-excluded-rows

Conversation

@yucheng-du

Copy link
Copy Markdown
Contributor

Fixes #1038.

With na.exclude, fitted values and deviance residuals can include placeholders for rows the model dropped. The response and predictor used to build the bins contain only the fitted rows. Reuse .fitted_rows() to align the vectors before calculating residuals or allocating the bins.

Added comparisons with na.omit for bins based on fitted values and on a named predictor. The binned-residual tests pass, and check_model() returns the same six bins for both fits in the reported example. R CMD check --no-manual passed with available suggested packages.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No actionable issues were found in the reviewed changes.

No open issues 🎉

What changed in this PR

Fixes binned_residuals() for na.exclude models by aligning fitted values and residuals with fitted observations.

Changes:

  • Applies .fitted_rows() to fitted values and deviance residuals.
  • Adds regression tests comparing na.exclude and na.omit.
  • Documents the fix in NEWS.md.
File Description
tests/​testthat/​test-binned_residuals.R Adds regression coverage comparing binned residuals for na.exclude and na.omit models.
R/​binned_residuals.R Aligns fitted values and deviance residuals with the rows used during model fitting.
NEWS.md Documents the na.exclude binned-residuals fix.

Review effort: Lite

@strengejacke

Copy link
Copy Markdown
Member

LGTM (and also LGTcopilot), thanks!

@strengejacke
strengejacke merged commit cad6af7 into easystats:main Dec 2, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

binned_residuals() fails for models fitted with na.action = na.exclude

3 participants